from numbers import pentagonal, isPentagonal

def isSumOf(nr, list):
    for a in list:
        for b in reversed(list):
            sum = a + b
            if sum > nr: break
            if sum == nr:
                if (b - a) in list:
                    print "FOUND: ",a,b,nr
            
    return False

def solution1():
    generator = pentagonal()
    found = []

    while True:
        next = generator.next()
        isSumOf(next, found)
        found.append(next)
        
def solution2():
    generator = pentagonal()
    found = set()
    limit = 100000
    
    for i in range(0, limit):
        found.add(generator.next())
        
    print "Generated list of first ", limit, " pentagonal numbers"
    
    for a in found:
        for b in found:
            if b > a:
                sum = a + b
                if sum in found:
                    difference = b - a
                    if difference in found:
                        print a,b

def solution3():
    generator = pentagonal()
    
    for p in generator:
        gen2 = pentagonal()
        for q in gen2:
            if q >= p: break
            if isPentagonal(p - q) and isPentagonal(p + q):
                print p,q, p -q 
                    
solution3()